<template>
    <div id="app">
        <div style="display: flex;">
            <div style="width: 250px;height: 300px ;border: 1px solid black;">
                <el-tree :data="formattedTreeData" accordion v-model="selectLocation"
                    @node-click="handleNodeClick"></el-tree>
            </div>
            <div style="margin-left: 20px;">
                设备编号 <el-input v-model="selectCode" style="width: 200px;"></el-input>
                设备名称 <el-input v-model="selectName" style="width: 200px;"></el-input>
                <el-button type="primary" style="height: 35px;" @click="getEwDeviceList(1)"><i
                        class="el-icon-search">搜索</i></el-button>
                <el-button style="height: 35px;" @click="reset"><i class="el-icon-refresh">重置</i></el-button>
                <div style="margin-top: 10px;">
                    <br>
                    <el-button type="primary" style="height: 32px;" @click.native="addEwDeviceValue"><i
                            class="el-icon-plus">新增设备</i></el-button>
                </div>
            </div>

        </div>
        <div style="position: absolute;left: 300px;top: 150px;">
            <el-table :data="sysEwDeviceList" style="width: 68%">
                <el-table-column prop="id" label="序号" width="100">
                </el-table-column>
                <el-table-column prop="device_name" label="设备名称" width="100">
                    <template slot-scope="scope">{{scope.row.deviceName}}</template>
                </el-table-column>
                <el-table-column prop="device_status" label="设备状态" width="130">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.deviceStatus === '0'" type="success">正常</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="device_location" label="设备位置" width="150">
                    <template slot-scope="scope">{{scope.row.deviceLocation}}</template>
                </el-table-column>
                <el-table-column prop="gateway_id" label="设备编号" width="100">
                    <template slot-scope="scope">{{scope.row.gatewayId}}</template>
                </el-table-column>
                <el-table-column prop="device_type" label="设备类型" width="110">
                    <template slot-scope="scope">{{scope.row.deviceType == 1? '电表':'水表'}}</template>
                </el-table-column>
                <el-table-column prop="device_balance" label="设备剩余金额" width="120">
                    <template slot-scope="scope">{{scope.row.deviceBalance}}</template>
                </el-table-column>
                <el-table-column prop="device_surplus" label="设备剩余量" width="120">
                    <template slot-scope="scope">{{scope.row.deviceSurplus}}</template>
                </el-table-column>
                <el-table-column prop="sluice_status" label="水表阀门状态" width="120">
                    <template slot-scope="scope">{{scope.row.sluiceStatus ==0? '拉闸':'合闸'}}</template>
                </el-table-column>
                <el-table-column prop="electricity_status" label="电表总状态" width="120">
                    <template slot-scope="scope">{{scope.row.electricityStatus ==0? '拉闸':'合闸'}}</template>
                </el-table-column>
                <el-table-column prop="electricity_a_status" label="电表A路状态" width="120">
                    <template slot-scope="scope">{{scope.row.electricityAStatus ==0? '拉闸':'合闸'}}</template>
                </el-table-column>
                <el-table-column prop="electricity_b_status" label="电表B路状态" width="120">
                    <template slot-scope="scope">{{scope.row.electricityBStatus ==0? '拉闸':'合闸'}}</template>
                </el-table-column>
                <el-table-column prop="create_time" label="入网时间" width="170">
                    <template slot-scope="scope">{{scope.row.createTime}}</template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="150">
                    <template slot-scope="scope">
                        <el-tooltip effect="dark" content="编辑" placement="top">
                            <el-button type="primary" icon="el-icon-edit" size="mini" circle
                                @click="refresh(scope.row)"></el-button>
                        </el-tooltip>
                        <el-tooltip effect="dark" content="删除" placement="top">
                            <el-button type="danger" icon="el-icon-delete" size="mini" circle
                                @click="del(scope.row.id)"></el-button>
                        </el-tooltip> 
                        <el-tooltip effect="dark" content="重新开户" placement="top">
                            <el-button type="danger" icon="el-icon-refresh" size="mini" circle
                                @click.native="ewDeviceInfo(scope.row.id,17)"></el-button>
                        </el-tooltip>
                        <el-tooltip effect="dark" content="操作" placement="top">
                            <el-dropdown trigger="click">
                                <el-button size="mini" type="info" icon="el-icon-setting" circle></el-button>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item icon="el-icon-bottom"
                                        @click.native="showEwDeviceInfo(scope.row.id,7)">获取电表参数</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-bottom"
                                        @click.native="getSysEwdevicelogShow(scope.row.id)">操作记录</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-bottom"
                                        @click.native="showEwDevice(scope.row.id,2)">拉总闸</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-top"
                                        @click.native="showEwDevice(scope.row.id,1)">合总闸</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-sort-down"
                                        @click.native="showEwDevice(scope.row.id,4)">拉A路闸</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-sort-up"
                                        @click.native="showEwDevice(scope.row.id,3)">合A路闸</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-arrow-down"
                                        @click.native="showEwDevice(scope.row.id,6)">拉B路闸</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-arrow-up"
                                        @click.native="showEwDevice(scope.row.id,5)">合B路闸</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-download"
                                        @click.native="showEwDevice(scope.row.id,16)">抄表</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
            <div style="margin-top: 30px;margin-left: 870px;" v-if="pageCount>=1">
                <el-button-group>
                    <el-button type="primary" icon="el-icon-arrow-left" @click="prevPage">上一页</el-button>
                    <el-button><span>{{pageNum}} / {{pageCount}}</span></el-button>
                    <el-button type="primary" @click="nextPage">下一页<i
                            class="el-icon-arrow-right el-icon--right"></i></el-button>
                </el-button-group>
            </div>
        </div>
        <el-row v-if="addEwDevice">
            <el-dialog title="添加设备信息" :visible.sync="addEwDevice" width="40%">
                <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="设备编号" prop="code">
                        <el-input v-model="form.code" style="width: 350px;"></el-input>
                    </el-form-item>
                    <el-form-item label="设备类型" prop="type">
                        <el-select v-model="form.type" style="width: 200px;height: 30px;">
                            <el-option label="电表" value="1">电表</el-option>
                            <el-option label="水表" value="2">水表</el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="设备名称" prop="name">
                        <el-input v-model="form.name" style="width: 200px;"></el-input>
                    </el-form-item>
                    <el-form-item label="空间位置" prop="location">
                        <el-cascader v-model="form.location" :options="formattedTreeData"
                            :props="{ checkStrictly: true }" clearable>
                        </el-cascader>
                    </el-form-item>
                </el-form>
                <div style="display: flex;gap: 10px;position: absolute;right: 20px;bottom: 0;height: 50px;">
                    <span slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="add('form')">确定</el-button>
                        <el-button @click="addEwDevice = false">取 消</el-button>
                    </span>
                </div>
            </el-dialog>
        </el-row>
        <el-row v-if="updEwDevice">
            <el-dialog title="修改设备信息" :visible.sync="updEwDevice" width="40%">
                <el-form :rules="updRules" ref="form" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="设备编号" prop="code">
                        <el-input v-model="code" style="width: 350px;"></el-input>
                    </el-form-item>
                    <el-form-item label="设备类型" prop="type">
                        <el-select v-model="type" style="width: 200px;height: 30px;">
                            <el-option label="电表" value="1">电表</el-option>
                            <el-option label="水表" value="2">水表</el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="设备名称" prop="name">
                        <el-input v-model="name" style="width: 200px;"></el-input>
                    </el-form-item>
                    <el-form-item label="空间位置" prop="location">
                        <el-cascader v-model="location" :options="formattedTreeData" :props="{ checkStrictly: true }"
                            clearable>
                        </el-cascader>
                    </el-form-item>
                    <el-form-item label="网关" prop="status">
                        <el-select v-model="gatewayId" style="width: 200px;height: 30px;">
                            <el-option v-for="row in sysGatewayList" :key="row.id" :label="row.id" :value="row.id">
                                {{ row.id }}
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
                <div style="display: flex;gap: 10px;position: absolute;right: 20px;bottom: 0;height: 50px;">
                    <span slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="upd('form')">确定</el-button>
                        <el-button @click="updEwDevice = false">取 消</el-button>
                    </span>
                </div>
            </el-dialog>
        </el-row>
        <el-row v-if="sysEwdevicelogShow">
            <el-dialog title="操作记录" :visible.sync="sysEwdevicelogShow" width="80%">
                <el-table :data="sysEwdevicelogList" stripe style="width: 100%">
                    <el-table-column prop="deviceCode" label="设备编号" width="180">
                    </el-table-column>
                    <el-table-column prop="operationUser" label="操作用户" width="180">
                    </el-table-column>
                    <el-table-column prop="operationContext" label="操作内容" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column prop="operationIp" label="操作IP">
                    </el-table-column>
                    <el-table-column prop="operationType" label="操作类型">
                    </el-table-column>
                    <el-table-column prop="createTime" label="操作时间">
                    </el-table-column>
                </el-table>
                <div style="margin-top: 30px;margin-left: 1000px;" v-if="pageCountEW>=1">
                    <el-button-group>
                        <el-button type="primary" icon="el-icon-arrow-left" @click="prevPageEw">上一页</el-button>
                        <el-button><span>{{pageNumEW}} / {{pageCountEW}}</span></el-button>
                        <el-button type="primary" @click="nextPageEw">下一页<i
                                class="el-icon-arrow-right el-icon--right"></i></el-button>
                    </el-button-group>
                </div>
            </el-dialog>
        </el-row>
        <el-row v-if="SysElectricityInfo">
            <el-dialog title="电表参数" :visible.sync="SysElectricityInfo" width="50%">
                <div v-loading="loading">
                    <el-row>
                        <el-col :span="8">
                            <el-card>
                                <span>A路电流: {{sysElectricityInfo.aCurrent}} A</span>
                            </el-card>
                        </el-col>
                        <el-col :span="8">
                            <el-card>
                                <span>A路功率: {{sysElectricityInfo.aPower}} KW</span>
                            </el-card>
                        </el-col>
                        <el-col :span="8">
                            <el-card>
                                <span>A路电压: {{sysElectricityInfo.aVoltage}} V</span>
                            </el-card>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-card>
                                <span>A路功率因数: {{sysElectricityInfo.aPowerFactor}}</span>
                            </el-card>
                        </el-col>
                        <el-col :span="8">
                            <el-card>
                                <span>A路视在功率: {{sysElectricityInfo.aApparentPower}} KVA</span>
                            </el-card>
                        </el-col>
                        <el-col :span="8">
                            <el-card>
                                <span>B路电流: {{sysElectricityInfo.bCurrent}} A</span>
                            </el-card>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-card>
                                <span>B路功率: {{sysElectricityInfo.bPower}} KW</span>
                            </el-card>
                        </el-col>
                        <el-col :span="8">
                            <el-card>
                                <span>B路电压: {{sysElectricityInfo.bVoltage}} V</span>
                            </el-card>
                        </el-col>
                        <el-col :span="8">
                            <el-card>
                                <span>B路功率因数: {{sysElectricityInfo.bPowerFactor}}</span>
                            </el-card>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-card>
                                <span>B路视在功率: {{sysElectricityInfo.bApparentPower}} KVA</span>
                            </el-card>
                        </el-col>
                        <el-col :span="8">
                            <el-card>
                                <span>总功率: {{sysElectricityInfo.sumPower}} KW</span>
                            </el-card>
                        </el-col>
                        <el-col :span="8">
                            <el-card>
                                <span>总视在功率: {{sysElectricityInfo.sumApparentPower}} KVA</span>
                            </el-card>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-card>
                                <span>电网频率: {{sysElectricityInfo.frequency}} HZ</span>
                            </el-card>
                        </el-col>
                    </el-row>
                </div>
            </el-dialog>
        </el-row>
    </div>
</template>
<script>
import axios from 'axios';
export default {
    name: 'app',
    data() {
        return {
            selectCode: '',
            selectName: '',
            pageCount: 0,
            pageNum: 1,
            pageSize: 5,
            sysDormitoryList: [],
            sysClassroomList: [],
            sysHostelList: [],
            selectLocation: '',
            selectLocationJoin: [],
            addEwDevice: false,
            formattedData: [],
            form: {
                code:'',
                name:'',
                type:'',
                location:''
            },
            id:'',
            code: '',
            gatewayId: '',
            name: '',
            type: '',
            location: '',
            updForm: {
                code:'',
                gatewayId:'',
                name:'',
                type:'',
                location:''
            },
            rules: {
                name: [
                    { required: true, message: '请输入设备名称', trigger: 'blur' },
                ],
                type: [
                    { required: true, message: '请输入设备类型', trigger: 'blur' },
                ],
                code: [
                    { required: true, message: '请输入设备编号', trigger: 'blur' },
                ],
                location: [
                    { required: true, message: '请选择空间位置', trigger: 'blur' },
                ]
            },
            updRules: {
            },
            sysEwDeviceList:[],
            showInfo:false,
            ewDevice:{},
            updEwDevice:false,
            sysEwdevicelog:{},
            sysGatewayList:[],
            //操作记录分页
            pageCountEW:'',
            sysEwdevicelogList:[],
            pageNumEW:1,
            pageSizeEW:10,
            sysEwdevicelogShow:false,
            //电表参数
            SysElectricityInfo:false,
            sysElectricityInfo:{},
            loading:false
        }
    },

    created() {
        this.getEwDeviceList(1);
        this.getSysDormitoryList();
        this.getSysClassroomList();
        this.getSysHostelAll();
    },
    computed: {
        formattedTreeData() {
            function addRoomsToLevelSysList(roomArray, itemId, floorNumber, levelSysList) {
                roomArray.forEach(room => {
                    if (room.dormitoryId === itemId &&
                        room.numberFloors === floorNumber) {

                        levelSysList.children.push({
                            label: room.locationName,
                            value: room.locationName
                        });
                    }
                });
            }

            const formattedData = [];
            const rooms = this.sysClassroomList; // 假设这是组件中的一个房间数组  
            const hostels = this.sysHostelList;
            if (rooms.length === 0) {
                return;
            }
            if (hostels.length === 0) {
                return;
            }
            function processData(data) {
                data.forEach(item => {
                    const sysDormitoryList = {
                        label: item.locationName,
                        value: item.locationName,
                        children: []
                    };

                    if (item.floorNumber) {
                        for (let i = 0; i < item.floorNumber; i++) {
                            const levelSysList = {
                                label: `${i + 1}楼`,
                                value: `${i + 1}楼`,
                                children: []
                            };
                            addRoomsToLevelSysList(rooms, item.id, i + 1, levelSysList);

                            // 调用函数处理hostels数组
                            addRoomsToLevelSysList(hostels, item.id, i + 1, levelSysList);

                            // 将构建好的楼层对象添加到楼栋的children数组中  
                            sysDormitoryList.children.push(levelSysList);
                        }
                    }

                    // 将构建好的楼栋对象添加到最终的formattedData数组中  
                    formattedData.push(sysDormitoryList);
                    console.log(formattedData)
                });

                return formattedData;
            }

            // 调用processData函数，并传入SysFloorList（这里假设它是组件的一个响应式数据属性）  

            return processData(this.sysDormitoryList);
        }
    },
    methods: {
        handleNodeClick(data, node) {
            this.selectLocationJoin = [];
            console.log(data.label);
            // 获取父节点（如果存在）  
            let parentNode = node.parent;
            let parentValue = null;
            let parentValue2 = null;
            if (parentNode) {
                // 父节点的数据对象  
                const parentData = parentNode.data;
                // 父节点的 value  
                parentValue = parentData.value;
                console.log(parentValue)

                let parentNode2 = parentNode.parent;
                if (parentNode2) {
                    // 父节点的数据对象  
                    const parentData2 = parentNode2.data;
                    // 父节点的 value  
                    parentValue2 = parentData2.label;
                    console.log("ascxadsxsdadcdsa" + parentValue2)
                    if (parentValue2 != null && parentValue2 != '') {
                        this.selectLocationJoin.push(parentValue2);
                    }
                }
                if (parentValue != null && parentValue != '') {
                    this.selectLocationJoin.push(parentValue);
                }
            }

            console.log(this.selectLocationJoin);

            this.selectLocationJoin.push(data.label);
            this.selectLocationJoin.join('/');
            console.log("aaaaaaaa" + this.selectLocationJoin.join('/'));
            this.getEwDeviceList(1);
        },
        getSysDormitoryList() {

            this.Authorization = localStorage.getItem("Authorization");
            axios({
                url: 'http://localhost:9002/sys/dormitory/getSysDormitoryList',
                method: 'post',
                headers: {
                    'Authorization': this.Authorization
                }
            })
                .then(response => {
                    this.sysDormitoryList = response.data.data;
                })


        },
        getSysClassroomList() {
            this.Authorization = localStorage.getItem("Authorization");
            axios({
                url: 'http://localhost:9002/sys/classroom/getSysClassroomAll',
                method: 'post',
                headers: {
                    'Authorization': this.Authorization
                }
            })
                .then(response => {
                    this.sysClassroomList = response.data.data;
                })
        },
        getSysHostelAll() {
            this.Authorization = localStorage.getItem("Authorization");
            axios({
                url: 'http://localhost:9002/sys/hostel/getSysHostelAll',
                method: 'post',
                headers: {
                    'Authorization': this.Authorization
                }
            })
                .then(response => {
                    this.sysHostelList = response.data.data;
                    console.log(this.sysHostelList);
                })
        },
        addEwDeviceValue() {
            this.form = {};
            this.addEwDevice = true;
        },
        add(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    let Authorization = localStorage.getItem("Authorization");
                    axios({
                        url: 'http://localhost:9002/sys/ewdevice/addEwDevice',
                        method: 'post',
                        data: {
                            deviceCode: this.form.code,
                            deviceName: this.form.name,
                            deviceType: this.form.type,
                            deviceLocation: this.form.location.join('/'),
                        },
                        headers: {
                            'Authorization': Authorization
                        }
                    })
                    .then(response => {
                        console.log(response);
                        if(response.data.status == 200){
                            this.$message.success('添加成功');
                            this.addEwDevice = false;
                            this.getEwDeviceList(1);

                        }else{
                            this.$message.error('添加失败');
                        }
                    })
                } else {
                    return false;
                }
            });

        },
        getEwDeviceList(pageNum){
            this.pageNum = pageNum;
            let aa;
            if(this.selectLocationJoin != ''){
                aa = this.selectLocationJoin.join('/');
            }else{
                aa = '';
            }
            let Authorization = localStorage.getItem("Authorization");
            axios({
                url: 'http://localhost:9002/sys/ewdevice/getEwDeviceList',
                method: 'post',
                params: {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                    gatewayId:this.selectCode,
                    deviceName: this.selectName,
                    location: aa
                },
                headers: {
                    'Authorization': Authorization
                }
            })
            .then(response => {
                this.sysEwDeviceList = response.data.data.sysEwDeviceList;
                this.pageCount = response.data.data.pageCount;
                console.log(this.sysEwDeviceList);
            })
        },
        prevPage() {
            this.pageNum--;
            var pageNum = this.pageNum;
            if (this.pageNum >= 1) {
                this.getEwDeviceList(pageNum);
            } else {
                this.getEwDeviceList(1);
            }
        },
        nextPage() {
            this.pageNum++;
            var pageNum = this.pageNum;
            if (this.pageNum <= this.pageCount) {
                this.getEwDeviceList(pageNum);
            } else {
                this.getEwDeviceList(this.pageCount);
            }
        },
        reset(){
            this.selectCode = '';
            this.selectName = '';
            this.selectLocationJoin = '';
            this.getEwDeviceList(1);
        },
        show(){
            this.showInfo = true;
        },
        refresh(row){
            console.log(row);
            this.updForm = row;
            this.id=row.id;
            this.location = row.deviceLocation.split('/');
            this.code = row.deviceCode;
            this.type = row.deviceType;
            this.gatewayId = row.gatewayId;
            this.name = row.deviceName;
            this.updEwDevice = true;
            this.getSysGateway();
            
        },
        getSysGateway(){
            let Authorization = localStorage.getItem("Authorization");
            axios({
                url: 'http://localhost:9002/sys/gateway/getSysGatewayList',
                method: 'post',
                params: {
                    pageNum: 1,
                    pageSize: 10000
                },
                headers: {
                    'Authorization': Authorization
                }
            })
                .then(response => {
                    this.sysGatewayList = response.data.data.sysGatewayList;
                    console.log(this.sysGatewayList);
                })  
        },
        upd(){
            if (this.code == '') {
                this.$message.error('设备编号不能为空');
                return;
            }
            if (this.name == '') {
                this.$message.error('设备名称不能为空');
                return;
            }
            if (this.type == '') {
                this.$message.error('设备类型不能为空');
                return;
            }
            let aa;
            if (this.location != '') {
                aa = this.location.join('/');
            } else {
                aa = '';
            }
            let Authorization = localStorage.getItem("Authorization");
            axios({
                url: 'http://localhost:9002/sys/ewdevice/updEwDevice',
                method: 'post',
                data: {
                    id: this.id,
                    deviceCode: this.code,
                    gatewayId: this.gatewayId,
                    deviceName: this.name,
                    deviceType: this.type,
                    deviceLocation: aa
                },
                headers: {
                    'Authorization': Authorization
                }
            })
                .then(response => {
                    console.log(response)
                    if (response.data.status == 200) {
                        this.$message.success('修改成功');
                        this.updEwDevice = false;
                        this.getEwDeviceList(1);
                    } else {
                        this.$message.error('修改失败');
                    }
                })
        },
        del(id){
            if (confirm("确定删除该条信息吗？")) {
                let Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/ewdevice/delEwDeviceById',
                    method: 'post',
                    params: {
                        id: id
                    },
                    headers: {
                        'Authorization': Authorization
                    }
                })
                    .then(response => {
                        console.log(response);
                        if (response.data.status == 200) {
                            this.$message.success('删除成功');
                            this.getEwDeviceList(1);
                        } else {
                            this.$message.error('删除失败');
                        }
                    })
            }
            
        },
        //发送指令
        showEwDevice(id,operationType){
            let Authorization = localStorage.getItem("Authorization");
            axios({
                url: 'http://localhost:9002/sys/ewdevice/electricity',
                method: 'post',
                params: {
                    operationType: operationType,
                    id: id,
                },
                headers: {
                    'Authorization': Authorization
                }
            })
            .then(response => {
                console.log(response);
                if (response.data.status == 200) {
                    this.$message.success('发送成功');
                }else{
                    this.$message.error('发送失败');
                }
            })
        },
        //电表参数
        showEwDeviceInfo(id,operationType){
            this.showEwDevice(id,operationType);
            this.SysElectricityInfo = true;
            setTimeout(() => {
                this.loading = true; // 开始加载，显示加载效果
                let Authorization = localStorage.getItem("Authorization");
                axios({
                    url: 'http://localhost:9002/sys/ewdevice/getSysElectricityInfo',
                    method: 'post',
                    params: {
                        id: id,
                    },
                    headers: {
                        'Authorization': Authorization
                    }
                })
              .then(response => {
                    let sysElectricityInfo = response.data.data;
                    this.sysElectricityInfo = JSON.parse(sysElectricityInfo);
                    console.log(this.sysElectricityInfo);
                    this.loading = false; // 加载完成，隐藏加载效果
                })
              .catch(error => {
                    console.error(error);
                    this.loading = false; // 出现错误，也隐藏加载效果
                });
            }, 2000);
        },
        //操作记录
        getSysEwdevicelogShow(id){
            this.sysEwdevicelogShow = true;
            this.id = id;
            this.getSysEwdevicelog(1);
        },
        getSysEwdevicelog(pageNum){
            this.pageNumEW = pageNum;
            let Authorization = localStorage.getItem("Authorization");
            axios({
                url: 'http://localhost:9002/sys/ewdevice/getSysEwdevicelog',
                method: 'post',
                params: {
                    ewDeviceId: this.id,
                    pageNum: this.pageNumEW,
                    pageSize: 10
                },
                headers: {
                    'Authorization': Authorization
                }
            })
            .then(response => {
                this.sysEwdevicelogList = response.data.data.sysEwdevicelogList;
                this.pageCountEW = response.data.data.pageCount;
                console.log(this.sysEwdevicelogList);
            })
        },
        //重新开户
        ewDeviceInfo(id,operationType){
            if (confirm("确定重新开户吗？")){
                this.showEwDevice(id,operationType);
            }
        },
        prevPageEw() {
            this.pageNumEW--;
            var pageNum = this.pageNumEW;
            if (this.pageNumEW >= 1) {
                this.getSysEwdevicelog(pageNum);
            } else {
                this.getSysEwdevicelog(1);
            }
        },
        nextPageEw() {
            this.pageNumEW++;
            var pageNum = this.pageNumEW;
            console.log(this.pageNumEW);
            if (this.pageNumEW <= this.pageCountEW) {
                this.getSysEwdevicelog(pageNum);
            } else {
                this.getSysEwdevicelog(this.pageCountEW);
            }
        },
    },

}
</script>
<style scoped>
 .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
.demonstration {
    display: block;
    color: #8492a6;
    font-size: 14px;
    margin-bottom: 20px;
  }
  body {
    margin: 0;
  }
</style>